#ifndef _QY_SPIN_LOCK_H
#define _QY_SPIN_LOCK_H

#include <pthread.h>
#include "Noncopyable.h"

//on Mac OS, alternative for pthread_spinlock_t is OSSpinLock, defined in <libkern/OSAtomic.h>

namespace qy
{

class SpinLock : public Noncopyable
{
public:
	SpinLock *create();
	void destroy(SpinLock *s);

	void lock();
	bool trylock();
	void unlock();

private:
	SpinLock(pthread_spinlock_t s);
	~SpinLock();

private:
	pthread_spinlock_t m_spinlock;


};

}

#endif
